package com.edu.medicalpro.mine;

import android.app.AlertDialog;
import android.content.ContentResolver;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.cardview.widget.CardView;

import com.edu.medicalpro.GeRenZhongXin.ChuanDaiSheBeiActivity;
import com.edu.medicalpro.GeRenZhongXin.JianChaBaoGaoDanActivity;
import com.edu.medicalpro.GeRenZhongXin.JianYanBaoGaoDanActivity;
import com.edu.medicalpro.GeRenZhongXin.JiuCanFuWuActivity;
import com.edu.medicalpro.GeRenZhongXin.JiuZhenRenLieBiaoActivity;
import com.edu.medicalpro.GeRenZhongXin.MeiRiQingDnaActivity;
import com.edu.medicalpro.GeRenZhongXin.MenZhenHuaFeiActivity;
import com.edu.medicalpro.GeRenZhongXin.QuHaoZhiFuActivity;
import com.edu.medicalpro.GeRenZhongXin.XinZengJiuZhenRenActivity;
import com.edu.medicalpro.GeRenZhongXin.YaoLiFangActivity;
import com.edu.medicalpro.GeRenZhongXin.ZhiNengHouZhenActivity;
import com.edu.medicalpro.R;
import com.edu.medicalpro.ZiDingYiView.ErWeiMaDialog;
import com.edu.medicalpro.base.BaseFragment;

import java.io.FileNotFoundException;

import static android.app.Activity.RESULT_OK;


public class InfoFragment extends BaseFragment {
    ImageView headPortrait;

    @Override
    protected void initView(View rootView) {
        //患者信息卡
        CardView xinXiKa=rootView.findViewById(R.id.xin_xi_ka);
        //头像
        headPortrait=rootView.findViewById(R.id.head_portrait);
        //患者名字
        TextView huanZheName=rootView.findViewById(R.id.huanzhename);
        //证件号
        TextView zhengJianNum=rootView.findViewById(R.id.zhengjiannum);
        //诊疗号
        TextView zhenLiaoNum=rootView.findViewById(R.id.zhenliaonum);
        //二维码
        ImageView erWeiMa=rootView.findViewById(R.id.er_wei_ma);
        //新增就诊人
        TextView xinZenJiuZhenRen=rootView.findViewById(R.id.xin_zeng_jiu_zhen);
        //取号支付
        ImageView quHaoZhiFu=rootView.findViewById(R.id.qu_hao_zhi_fu_img);
        //检验报告单
        ImageView jianYnaBaoGaoDan=rootView.findViewById(R.id.jian_yan_bao_gao_dan_img);
        //检查报告单
        ImageView jianChaBaoGaoDan=rootView.findViewById(R.id.jian_cha_bao_gao_img);
        //门诊花费
        ImageView menZhenHuaFei=rootView.findViewById(R.id.men_zhen_hua_fei_img);
        //每日清单
        ImageView meiRiQingDan=rootView.findViewById(R.id.mei_ri_qing_dan_img);
        //智能候诊
        ImageView zhiNengHouZhen=rootView.findViewById(R.id.zhi_neng_hou_zhen_img);
        //就餐服务
        ImageView jiuCanFuWu=rootView.findViewById(R.id.jiu_can_fu_wu_img);
        //药立方
        ImageView yaoLiFang=rootView.findViewById(R.id.yao_li_fang_img);
        //穿戴设备
        ImageView chuanDaiSheBei=rootView.findViewById(R.id.chuan_dai_img);
        //信息卡点击事件
        xinXiKa.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(requireActivity(), JiuZhenRenLieBiaoActivity.class);
                startActivity(intent);
            }
        });
        //头像点击事件
        headPortrait.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //更换头像
                Intent intent = new Intent();
                /* 开启Pictures画面Type设定为image */
                intent.setType("image/*");
                /* 使用Intent.ACTION_GET_CONTENT这个Action */
                intent.setAction(Intent.ACTION_GET_CONTENT);
                /* 取得相片后返回本画面 */
                startActivityForResult(intent, 1);
            }
        });
        //二维码点击事件
        erWeiMa.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // 创建一个AlertDialog.Builder对象
                ErWeiMaDialog.Builder builder = new ErWeiMaDialog.Builder(requireActivity());

                // 设置弹框标题
                builder.setLiftText("电子就诊卡", new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                    }
                });

                builder.setRightText("诊疗号", new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                    }
                });
                // 创建ErWeiMaDialog对象并显示
                ErWeiMaDialog dialog = builder.create();
                dialog.show();
            }
        });
        //新增就诊人点击事件
        xinZenJiuZhenRen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(requireActivity(), XinZengJiuZhenRenActivity.class);
                startActivity(intent);
            }
        });
        //取号支付点击事件
        quHaoZhiFu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(requireActivity(), QuHaoZhiFuActivity.class);
                startActivity(intent);
            }
        });
        //检验报告单点击事件
        jianYnaBaoGaoDan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(requireActivity(), JianYanBaoGaoDanActivity.class);
                startActivity(intent);
            }
        });
        //检查报告单点击事件
        jianChaBaoGaoDan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(requireActivity(), JianChaBaoGaoDanActivity.class);
                startActivity(intent);
            }
        });
        //门诊花费点击事件
        menZhenHuaFei.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(requireActivity(), MenZhenHuaFeiActivity.class);
                startActivity(intent);
            }
        });
        //每日清单点击事件
        meiRiQingDan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(requireActivity(), MeiRiQingDnaActivity.class);
                startActivity(intent);
            }
        });
        //智能候诊点击事件
        zhiNengHouZhen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(requireActivity(), ZhiNengHouZhenActivity.class);
                startActivity(intent);
            }
        });
        //就餐服务点击事件
        jiuCanFuWu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(requireActivity(), JiuCanFuWuActivity.class);
                startActivity(intent);
            }
        });
        //药立方点击事件
        yaoLiFang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(requireActivity(), YaoLiFangActivity.class);
                startActivity(intent);
            }
        });
        //穿戴设备点击事件
        chuanDaiSheBei.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(requireActivity(), ChuanDaiSheBeiActivity.class);
                startActivity(intent);
            }
        });

    }
    //讲从图库拿到的图片显示到image View上
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            Uri uri = data.getData();
            ContentResolver cr = (requireActivity()).getContentResolver();
            try {
                Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri));

                /* 将Bitmap设定到ImageView */
                headPortrait.setImageBitmap(bitmap);
            } catch (FileNotFoundException e) {
                Log.e("Exception", e.getMessage(),e);
            }
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_info;
    }

    @Override
    protected void initData() {

    }
}